package com.example.dingdong.config;

import com.example.dingdong.constant.Constants;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 处理静态资源的配置类
 * 通过这个配置类，将请求路径映射到指定的资源位置
 **/
@Configuration
public class WebPicConfig implements WebMvcConfigurer {

    /**
     * 配置资源处理器，将请求路径映射到实际的资源路径
     *
     * @param registry 资源处理器注册表
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 映射请求路径"/img/avatorImages/**"到实际路径
        registry.addResourceHandler("/img/avatorImages/**")
                .addResourceLocations(Constants.AVATOR_IMAGES_PATH);
        // 映射请求路径"/img/singerPic/**"到实际路径
        registry.addResourceHandler("/img/singerPic/**")
                .addResourceLocations(Constants.SINGER_PIC_PATH);
        // 映射请求路径"/img/songPic/**"到实际路径
        registry.addResourceHandler("/img/songPic/**")
                .addResourceLocations(Constants.SONG_PIC_PATH);
        // 映射请求路径"/song/**"到实际路径
        registry.addResourceHandler("/song/**")
                .addResourceLocations(Constants.SONG_PATH);
        // 映射请求路径"/img/songListPic/**"到实际路径
        registry.addResourceHandler("/img/songListPic/**")
                .addResourceLocations(Constants.SONGLIST_PIC_PATH);
        // 映射请求路径"/img/swiper/**"到实际路径
        registry.addResourceHandler("/img/swiper/**")
                .addResourceLocations(Constants.BANNER_PIC_PATH);
    }

}
